home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / gigo0714.zip / MUNGE.PAS < prev    next >
Pascal/Delphi Source File  |  1995-06-11  |  7KB  |  197 lines

  1.  
  2. Area : Jason's Netmail
  3.  
  4. Date : Jun 10 '95, 22:29                                                   pvt 
  5. From : hamish@cloud.apana.org.au                                 1:203/2
  6. To   : Jason Fesler                                           1:203/7707
  7. Subj : Waffle munging etc                                                    
  8. ────────────────────────────────────────────────────────────────────────────────
  9.  
  10. @MSGID: mid__4881CF31@cloud.apana.org.au c2140001
  11. @PID GIGO+ sn 1 at gigo vsn 0.99.950303
  12. A while back, you asked about getting my Waffle munging source in Pascal ..
  13.  
  14. Saturday May 27 1995 18:05, Hamish Moffatt wrote:
  15.  
  16.  HM>> Or if anyone's interested, I have pascal code available ...
  17.  HM>> (implemented from those Waffle docs you're obviously not
  18.  HM>> fond of Jason :-)
  19.  
  20.  > Cute :-)   If you get the chance, any possibility of emailing them?
  21.  > A lot of people are Pascal lovers (I'm just a closet Pascal lover), and
  22.  > would find that source to be useful..
  23.  
  24. I've just dressed it up (like written comments, rewrote lots of it in more 
  25. mathematical ways, for nicety reasons). I wrote it QUITE a few years ago, so 
  26. documenting it has been quite an exercise. Working out why it was calculating 
  27. the bitmask on the last five characters of the filename BACKWARDs, etc. Seems 
  28. to work, tested it on the Waffle manual's examples and some actual filenames 
  29. from my log. And I've learnt a fair bit about programming in those few years 
  30. (was 16 then :-)
  31.  
  32. It's still complicated enough, but certainly no worse than the Waffle manual, 
  33. which is where I wrote it from. And if you're writing internet-type software 
  34. like your GIGO or my interRA, that's not for the faint of heart anyway :-)
  35.  
  36. As to closet Pascal lovers, I'm a bit of a closet Ada lover, though I haven't 
  37. yet found the need to implement it in Ada. Would be much like the Pascal 
  38. source though.. If you ever get asked for munge source in Ada just drop me a 
  39. line :-)
  40.  
  41. Here's the source. (Not a unit or program, but rather more just an include 
  42. file. End user should package up as appropriate. Includes free power 
  43. function! Unfortunately Pascal has no ** operator).
  44.  
  45.  
  46. { Munge converts a unix-type filename found in a UUCP C or X file,
  47.   of the form D.ozoneB7n72, into a DOS filename, using the same
  48.   algorithm used in Waffle, FX UUCICO etc. From the description
  49.   in the Waffle documentation:
  50.  
  51.   For conversion, the prefix is moved to the end of the filename,
  52.   and the system name is stripped off. An extra byte is added to
  53.   prevent collisions due to DOS's handling (or lack thereof) of
  54.   mixed case filenames.
  55.  
  56.       D.ozoneBC0312   ->   /SPOOL/OZONE/0BC0312.D
  57.       X.ozoneBC0312   ->   /SPOOL/OZONE/0XC0212.X
  58.  
  59.   You will notice a leading "0" before the filename. This is a
  60.   bitmask of the alphabetic case of the remaining characters.
  61.  
  62.   In this example below, the bitmasks are "4" and "6" respectively:
  63.  
  64.       D.ozoneB7n72    ->   /SPOOL/OZONE/4S7N72.D
  65.       X.ozoneX7pt0    ->   /SPOOL/OZONE/6X7PT0.X
  66.  
  67.   To construct the bitmask, give all lowercase characters a value
  68.   of 1 and all uppercase or numeric value 0; do not include the
  69.   hostname when forming the bitmap. Also use only the last five
  70.   characters when constructing the bitmask. When taken together, the
  71.   the numeric value of the bitmask is the value of the leading byte.
  72.   If this exceeds 9, use the letters A through Z as necessary.
  73.  
  74.   This pascal implementation is public domain.
  75.   Written by Hamish Moffatt, hamish@rising.com.au,
  76.   released June 11, 1995.
  77.  
  78. }
  79.  
  80. { Power raises a byte i to the jth power
  81.   Parameters: two bytes, returns a longint
  82.   This is required when calculating the bit mask.
  83. }
  84.  
  85. Function power(i, j : byte) : longint;
  86. var
  87.   k    : byte;     { Counter }
  88.   temp : longint;  { Working power }
  89.  
  90. begin
  91.   temp := 1;
  92.  
  93.   { Multiple power by i, j times }
  94.   for k := 1 to j do
  95.     temp := temp * i;
  96.  
  97.   power := temp;
  98.  
  99. end;
  100.  
  101. { Munge does the actual filename munging.
  102.    Parameters:
  103.    filename      : filename to convert;
  104.    remote_system : name of remote system (one word UUCP name,
  105.                    eg cloud, rather than cloud.apana.org.au)
  106. }
  107.  
  108. function munge(filename, remote_system : string) : string;
  109.  
  110. var
  111.   filetype : char;
  112.   bitmask  : byte;
  113.   counter  : byte;
  114.   lastfive : string;
  115.  
  116. const
  117.  
  118.   { Table of characters used when converting the calculated bitmask
  119.     back into ASCII. This could be done a bit more mathematically,
  120.     for those so inclined (or those feeling the need for excessive speed). }
  121.  
  122.   mungetab : array[0..35] of char = ('0', '1', '2', '3', '4', '5', '6', '7',
  123.        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  124.        'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
  125.  
  126. begin
  127.  
  128.   { Only the first seven characters of the system name are ever used
  129.     in filenames, so we must remove anything left over. }
  130.  
  131.   delete(remote_system, 8, length(remote_system) - 7);
  132.  
  133.   { The file type (generally C, D or X) is not used in munging, but
  134.     should be passed back to the calling routine. Hence we store
  135.     it away and remove it from the working filename. }
  136.  
  137.   filetype := filename[1];
  138.   delete(filename, 1, 2);
  139.  
  140.   { If the remote system name is found at the start of the filename,
  141.     remove it; it is not used in the calculation. }
  142.  
  143.   if pos(remote_system, filename) = 1 then
  144.     delete(filename, 1, length(remote_system));
  145.  
  146.   { Only the last five characters of the filename are used in
  147.     the bitmask calculation, and they are needed in reverse order }
  148.  
  149.   lastfive := copy(filename, length(filename) - 5, 5);
  150.  
  151.   { For each character in the filename, add 2^(position-1) if the character
  152.     is lower case. If not lower case, do nothing. This calculates the
  153.     actual bitmask. }
  154.  
  155.   bitmask := 0;
  156.  
  157.   for counter := 1 to 5 do
  158.     if lastfive[counter] in ['a'..'z'] then
  159.       bitmask := bitmask + power(2, 5-counter);
  160.  
  161.   { "5-counter" is because the last character of the filename
  162.     contributes the least significant bit in the bitmask. }
  163.  
  164.  
  165.   { Concatenate the final filename; first the bitmask, which is
  166.     looked up in the table above for ASCII conversion; then
  167.     the five remaining characters of the original filename,
  168.     then a period and the filetype. }
  169.  
  170.   munge := concat(mungetab[bitmask], filename, '.', filetype);
  171.  
  172. end;
  173.  
  174.  
  175.  
  176. --- Email headers follow ---
  177. Apparently-to: jfesler@gigo.com
  178. X-Delivered-From: Unknown_IP_Address_203.12.22.20
  179. X-Received-By OS/2 SMTP Daemon v0.1ß/gigo
  180. Received: gigo.com Sun Jun 11 12:31:48 1995
  181. Received: from cloud.UUCP (Ucloud@localhost) by connexus.apana.org.au
  182. (8.6.9/8.6.9) with UUCP id FAA05522 for gigo.com!jfesler; Mon, 12 Jun 1995
  183. 05:06:38 +1000
  184. Received: by cloud.apana.org.au (0.55/interRA)
  185.         via UUCP; Sun, 11 Jun 1995 16:29:00 +1100
  186.         for jfesler@gigo.com
  187. To: jfesler@gigo.com
  188. Subject: Waffle munging etc
  189. From: hamish@cloud.apana.org.au (Hamish Moffatt)
  190. Message-Id: <4881CF31@cloud.apana.org.au>
  191. Date: Sun, 11 Jun 1995 16:29:00 +1100
  192. Organization: Cloud Nine BBS, Melbourne, Australia
  193.  
  194.  
  195. --- GIGO+ sn 1 at gigo vsn 0.99.950303
  196. VIA GIGO 1:203/2, Sun Jun 11 1995  at 20:32 
  197.